﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace verk2013_project_group12.Models
{
    public class UserRepository
    {
        AppDataContext db = new AppDataContext();
        public IEnumerable<UserProfile> GetAllUsers()
        {
            return db.UserProfiles;
        }

        public UserProfile GetUserById(int id)
        {
            var theUser = (from u in db.UserProfiles
                              where u.UserId == id
                              select u).SingleOrDefault();
            return theUser;
        }

        public UserProfile GetUserByUsername(string username)
        {
            var theUser = (from u in db.UserProfiles
                           where u.UserName == username
                           select u).SingleOrDefault();
           
            return theUser;
        }

        public void Save()
        {
            db.SaveChanges();
        }


        public void DeleteUser(UserProfile user)
        {
            if (user != null)
            {
                db.UserProfiles.Remove(user);
            }
        }
    }
}